#include "button.h"
#include <QPaintEvent>
#include <QPainter>
#include <QDebug>

Button::Button(QWidget * parent) :
        QPushButton(parent),
        my_draw_item(none)
{
    setMinimumSize(QSize(50,50));
    setMaximumSize(QSize(100,100));

    connect(this, SIGNAL(clicked()),
            this, SLOT(click()));
}

QSize Button::sizeHint()
{
    static QSize size(50,50);
    return size;
}

void Button::setDrawItem(DrawnItem draw_item)
{
    my_draw_item = draw_item;
    emit update();
}
const Button::DrawnItem Button::getDrawItem() const
{
    return my_draw_item;
}


void Button::paintEvent(QPaintEvent * e)
{
    QPainter painter(this);
    painter.setBrush(Qt::white);
    QPolygon square(rect());
    painter.drawPolygon(square);

    switch(my_draw_item)
    {
    case none:
        break;
    case cross:
        painter.setBrush(Qt::black);
        painter.drawLine(0, 0,
                         this -> rect().width(),
                         this -> rect().height());
        painter.drawLine(this -> rect().width(), 0,
                         0, this -> rect().height());
        break;
    case toe:
        painter.setBrush(Qt::black);
        painter.drawArc(this -> rect(), 0,  (16 * 360));
        break;
    }
}


void Button::click()
{
    emit buttonclick(this);
    emit stateChanged();
}
